package cn.itcast.embedding;

import com.google.errorprone.annotations.Var;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import org.springframework.ai.document.Document;
import org.springframework.ai.reader.JsonReader;
import org.springframework.ai.transformer.splitter.TextSplitter;
import org.springframework.ai.transformer.splitter.TokenTextSplitter;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author shd
 * @version V1.0
 * @date 2025-04-21 1:59
 */
@Component
@RequiredArgsConstructor
public class PackageEmbedding {
    private final VectorStore vectorStore;

    @Value("classpath:rule.json")
    private Resource resource;

    @PostConstruct
    public void init() {
        var reader = new JsonReader(resource);
        List<Document> list = reader.get();
        //TextSplitter textSplitter = new TokenTextSplitter(300, 10, 20, 10000, false);
        TokenTextSplitter textSplitter = new TokenTextSplitter();
        List<Document> split = textSplitter.apply(list);
        vectorStore.add(split);
    }

}
